package com.alex.utils.http;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

public class DefaultHttpResult implements HttpResult {

	private HttpResponse response;
	
	private String finalUrl;
	
	DefaultHttpResult(HttpResponse response, String finalUrl) {
		this.response = response;
		this.finalUrl = finalUrl;
	}
	
	public HttpResponse getResponse() {
		return response;
	}
	
	public String getResponseBodyAsString() throws IOException {
		return HttpUtils.toString(response);
	}
	
	public void close() throws IOException {
		EntityUtils.consume(response.getEntity());
	}

	public byte[] getResponseBodyAsByteArray() throws IOException {
		return HttpUtils.toByteArray(response);
	}

	@Override
	public String getFinalURL() {
		return finalUrl;
	}
}
